package leetcode;

import java.util.Arrays;

public class Q2574 {
    public int[] leftRigthDifference(int[] nums) {
        int[] res = new int[nums.length];
        int[] left = new int[nums.length + 1];
        int[] right = new int[nums.length + 1];

        for (int i = 1; i < left.length; i++) {
            left[i] = left[i - 1] + nums[i - 1];
        }

        for (int i = right.length - 2; i >= 0; i--) {
            right[i] = right[i + 1] + nums[i];
        }

        for (int i = 0; i < nums.length; i++) {
            res[i] = Math.max(left[i + 1], right[i]) - Math.min(left[i + 1], right[i]);
        }

        return res;
    }

    public static void main(String[] args) {
        Q2574 sl = new Q2574();
        int[] nums = {10, 4, 8, 3};
        System.out.println(Arrays.toString(sl.leftRigthDifference(nums)));
    }
}